///////////////////////////////////////////////////
// Election Administration Polarization
// Joint Policy RD Table, Democratic Counties Only
///////////////////////////////////////////////////

gl path "~/Library/CloudStorage/GoogleDrive-danmckinleythompson@gmail.com/My Drive/ElecAdminPolarization/How_Partisan_Is_Local_Election_Admin_Replication"

* Bring in the turnout and registration analysis data
use "$path/analysis_data/rd_reg_turnout_analysis_data.dta", clear

//
/// overall
//

// Polling places
rdrobust r_eavs_polling_places_per1k rv if lag_vs_dem>0.5 & lag_vs_dem!=., vce(cluster election_id)
rdtab r_eavs_polling_places_per1k treat rv election_id, est_command("rdrobust") new("D")
sum eavs_polling_places_per1k if lag_vs_dem>0.5
local m1_d = r(mean)

// Provisionals
rdrobust r_prov_rate rv if lag_vs_dem>0.5 & lag_vs_dem!=., vce(cluster election_id)
rdtab r_prov_rate treat rv election_id, est_command("rdrobust") old("D")
sum prov_rate if lag_vs_dem>0.5
local m2_d = r(mean)

// Provisionals rejected
rdrobust r_prov_rejection_rate rv if lag_vs_dem>0.5 & lag_vs_dem!=., vce(cluster election_id)
rdtab r_prov_rejection_rate treat rv election_id, est_command("rdrobust") old("D")
sum prov_rejection_rate if lag_vs_dem>0.5
local m3_d = r(mean)

// Absentee rejection rate
rdrobust r_eavs_absentee_rej_rate rv if lag_vs_dem>0.5 & lag_vs_dem!=., vce(cluster election_id)
rdtab r_eavs_absentee_rej_rate treat rv election_id, est_command("rdrobust") old("D")
sum eavs_absentee_rej_rate if lag_vs_dem>0.5
local m4_d = r(mean)

// Registration
rdrobust r_registered_pc rv if lag_vs_dem>0.5 & lag_vs_dem!=., vce(cluster election_id)
rdtab r_registered_pc treat rv election_id, est_command("rdrobust") old("D")
sum registered_pc if lag_vs_dem>0.5
local m5_d = r(mean)

// Registration removal rate
rdrobust r_eavs_reg_removal_rate rv if lag_vs_dem>0.5 & lag_vs_dem!=., vce(cluster election_id)
rdtab r_eavs_reg_removal_rate treat rv election_id, est_command("rdrobust") old("D")
sum eavs_reg_removal_rate if lag_vs_dem>0.5
local m6_d = r(mean)

// Dem registration share
rdrobust r_reg_dem_share rv if lag_vs_dem>0.5 & lag_vs_dem!=., vce(cluster election_id)
rdtab r_reg_dem_share treat rv election_id, est_command("rdrobust") old("D")
sum reg_dem_share if lag_vs_dem>0.5
local m7_d = r(mean)

// Wait times r_wait_over30
rdrobust r_wait_over30 rv if lag_vs_dem>0.5 & lag_vs_dem!=., vce(cluster election_id)
rdtab r_wait_over30 treat rv election_id, est_command("rdrobust") old("D")
sum wait_over30 if lag_vs_dem>0.5
local m8_d = r(mean)


//
// party-specific regression tables (incl. overall)
// for prod
//

** table on democrat majority counties
qui {
* Build the memo/paper table
cap log close
set linesize 255
log using "$path/output/rd_table_policy_democrat.tex", text replace
noi di "\begin{table}[t]"
noi di "\centering"
noi di "\caption{\textbf{Effect of Democratic Election Officials on Policies and More Proximate Outcomes (Democrat Majority Counties Only).}"
noi di "\label{tab:rd_table_policy_democrat}}"
noi di "\begin{tabular}{lcccccccc}"
noi di "\toprule \toprule"
noi di " & Polling 	& Prov		& Prov		& Absentee	& Reg	& Reg		& Dem Reg 	& Wait  \\"
noi di " & Places	& Share		& Rejection	& Rejection	& Rate	& Removal	& Share		& Share \\"
noi di " & (1)		& (2)		& (3)		& (4)		& (5)	& (6)		& (7)		& (8)   \\"
noi di "\midrule"
noi di "Dem Elec Official & " %4.3f D[1,1] " & " %4.3f D[1,2] " & " %4.3f D[1,3] " & " %4.3f D[1,4] " "
noi di 		" & " %4.3f D[1,5] " & " %4.3f D[1,6] " & " %4.3f D[1,7] " & " %4.3f D[1,8] "\\"
noi di " & (" %4.3f D[2,1] ") & (" %4.3f D[2,2] ") & (" %4.3f D[2,3] ") & (" %4.3f D[2,4] ") "
noi di 		" & (" %4.3f D[2,5] ") & (" %4.3f D[2,6] ") & (" %4.3f D[2,7] ") & (" %4.3f D[2,8] ") \\[2mm]"
noi di "\midrule"
noi di "N & " %4.0f D[3,1] " & " %4.0f D[3,2] " & " %4.0f D[3,3] " & " %4.0f D[3,4] " "
noi di 	" & " %4.0f D[3,5] " & " %4.0f D[3,6] " & " %4.0f D[3,7] " & " %4.0f D[3,8] " \\ "
noi di "Clusters & " %4.0f D[4,1] " & " %4.0f D[4,2] " & " %4.0f D[4,3] " & " %4.0f D[4,4] " "
noi di 	" & " %4.0f D[4,5] " & " %4.0f D[4,6] " & " %4.0f D[4,7] " & " %4.0f D[4,8] " \\ "
noi di "Outcome Mean & " %4.3f `m1_d' " & " %4.3f `m2_d' " & " %4.3f `m3_d' " & " %4.3f `m4_d' " "
noi di 	" & " %4.3f `m5_d' " & " %4.3f `m6_d' " & " %4.3f `m7_d' " & " %4.3f `m8_d' " \\ "
noi di "Bandwidth & " %4.2f D[5,1] " & " %4.2f D[5,2] " & " %4.2f D[5,3] " & " %4.2f D[5,4] " "
noi di 	" & " %4.2f D[5,5] " & " %4.2f D[5,6] " & " %4.2f D[5,7] " & " %4.2f D[5,8] " \\ "
noi di "BW Selection & CCT & CCT & CCT & CCT & CCT & CCT & CCT & CCT \\"
noi di "Kernel & Tri & Tri & Tri & Tri & Tri & Tri & Tri & Tri \\"
noi di "\bottomrule \bottomrule"
noi di "\multicolumn{9}{p{1.1\textwidth}}{\footnotesize Robust standard errors clustered by clerk election in parentheses. "
noi di "The outcome is first regressed on a state- and year-specific lag using all counties including those for which clerk election "
noi di "results are not available. The regression discontinuity is estimated using the residuals from that regression. "
noi di "The bandwidth row reports the number of maximum clerk win margin allowed for inclusion in each specificaiton. "
noi di "CCT refers to \cite{calonico2014robust} bandwidth selection procedure."
noi di "Tri refers to a triangular kernel."
noi di "Democrat counties are those in which the Democratic clerk candidate's vote share is greater than 0.50.}"
noi di "\end{tabular}"
noi di "\end{table}"
log off
}
